$(() => {
    findById(id);
});

//查询指定id的学生信息
function findById(id) {
    $.ajax({
        url: ctx + "/admin/subject/id",
        method: "get",
        data: {
            id
        },
        success(resp) {
            const sub = resp.subject;
            $("#name").val(sub.name);
            $("#description").val(sub.description);
        }
    });
}

//修改
function submit(cb = $.noop) {
    let name = $("#name").val();
    let description = $("#description").val();


    //前端校验：js校验
    if (name.trim() === "") {
        layer.msg("名称不可为空");
        return;
    }


    $.ajax({
        url: ctx + "/admin/subject/edit",
        method: "post",
        data: {
            id,
            name,
            description
        },
        success(resp) {
            cb(resp.success);
        }
    });


}